
import pytest
from requests import Session

from api.admin.user_action import Update_userinfo
from api.order.order_action import Order_action
from api.order.CycleOrder_action import CycleOrder_action
from common.read_yaml import get_yaml_filepath
from common.logintoken import login_test
from api.admin.member_controller_api import MemberControllerApi
from common.read_config import test_token, num_test_token

data = get_yaml_filepath(Environ='data.yaml')  # 读取config下的data数据
from typing import List
def pytest_collection_modifyitems(
    session: "Session", config: "Config", items: List["Item"]
) -> None:
    for item in items:
        item.name = item.name.encode('utf-8').decode('unicode-escape')
        item._nodeid = item.nodeid.encode('utf-8').decode('unicode-escape')
"""---------------获取账号数据----------------------"""
@pytest.fixture(scope="session")
def test_user_info():
    return data["test_user"]

# @pytest.fixture(scope="session")
# def test2_user_info():
#     return data["test2_user"]

"""---------------进行初始化登录---------------------"""

@pytest.fixture(scope="session",autouse=True)
def atest_login(test_user_info):
    login_test(test_user_info,"test_token")

# @pytest.fixture(scope="session",autouse=True)
# def lisi_login(test2_user_info):
#     login_test2(test2_user_info,"test2_token")

"""---------------调用api进行token身份的切换---------------------"""
"""test1角色模块"""
@pytest.fixture(scope="session")
def membercontroller_s():
    return MemberControllerApi(test_token)

@pytest.fixture(scope="session")
def user_action():
    # print('ini中的token11',test_token)
    return Update_userinfo(num_test_token)


"""test2角色模块"""
# @pytest.fixture(scope="session")
# def membercontroller_l():
#     return MemberControllerApi(test2_token)
#
# @pytest.fixture(scope="session")
# def user2_action():
#     return Update_userinfo(num2_test_token)

"""---------------单笔订单操作---------------------"""
@pytest.fixture(scope="session")
def order_action():
    return Order_action(num_test_token)

"""---------------周期订单操作---------------------"""
@pytest.fixture(scope="session")
def cycle_order_action():
    return CycleOrder_action(num_test_token)

